package com.share.service.attach.advertise.impl;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.share.bean.attach.advertise.Advertise;
import com.share.dao.attach.advertise.AdvertiseDao;
import com.share.service.attach.advertise.AdvertiseManager;

@Service
public class AdvertiseManagerImpl implements AdvertiseManager {
	
	@Resource
	private AdvertiseDao adDao ;

	public void setAdDao(AdvertiseDao adDao) {
		this.adDao = adDao;
	}

	@Override
	public void deleteAdvertiseManager(int... ids) throws Exception {
		this.adDao.deleteAdvertiseDao(ids) ;
	}

	@Override
	public List<Advertise> findAllAdvertiseManager(int pid) throws Exception {
		String hql = "select o from Advertise o" ;
		
		StringBuffer sb = new StringBuffer() ;
		sb.append("o.pi_ad_id=?") ;
		
		List<Object> param = new ArrayList<Object>() ;
		param.add(pid) ;
		
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>() ;
		orderby.put("id","asc") ;
		
		return this.adDao.findAllAdvertiseDao(hql,sb.toString(), param,orderby) ;
	}

	@Override
	public Advertise loadByIdAdvertiseManager(int id) throws Exception {
		
		return this.adDao.loadByIdAdvertiseDao(id) ;
	}

	@Override
	public void saveAdvertiseManager(Advertise ad) throws Exception {
		this.adDao.saveAdvertiseDao(ad) ;
	}

	@Override
	public void updateAdvertiseManager(Advertise ad) throws Exception {
		this.adDao.updateAdvertiseDao(ad) ;
	}

}
